package kuzmenkov.oip.model.dao.hibernate.impl;

import kuzmenkov.oip.model.Module;
import kuzmenkov.oip.model.Parameter;
import kuzmenkov.oip.model.dao.hibernate.ParameterDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.springframework.dao.DataAccessException;

import java.util.List;

/**
 * @see kuzmenkov.oip.model.dao.hibernate.ParameterDao
 * User: Michael Kuzmenkov
 * Date: 16.03.2009
 * Time: 12:05:03
 */
public class ParameterDaoImpl extends GenericDaoImpl<Parameter, Long> implements ParameterDao {

    /**
     * @see kuzmenkov.oip.model.dao.hibernate.ParameterDao#findByModule(Long) 
     */
    public List<Parameter> findByModule(Long moduleId) throws DataAccessException {
        DetachedCriteria criteria = DetachedCriteria.forClass(Parameter.class);
        criteria.add(Expression.eq("moduleId", moduleId));

        Order order = Order.asc("position");
        criteria.addOrder(order);

        List<Parameter> params = getHibernateTemplate().findByCriteria(criteria);

        return params;
    }
}